//
//  SEGAddressView.m
//  账单测试
//
//  Created by 刘山 on 2016/12/12.
//  Copyright © 2016年 刘山. All rights reserved.
//

#import "SEGAddressView.h"

@implementation SEGAddressView

- (instancetype)init {
    if (self == [super init]) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self == [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


- (void)setupUI {
    self.userInteractionEnabled = YES;

    [self addSubview:self.picImageView];
    [self addSubview:self.contentLabel];
    [self addSubview:self.titleBtn];
    [self addSubview:self.arrowImageView];

    [self.picImageView setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"icon_location")]];
    self.picImageView.contentMode = UIViewContentModeCenter;
    [self.picImageView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).mas_offset(15);
        make.width.mas_equalTo(15);
    }];
    
    [self.contentLabel setFont:kFont_16];
    [self.contentLabel setTextColor:kColor_1];

    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.equalTo(self);
        make.width.mas_equalTo(12);
    }];

    [self.titleBtn mas_makeConstraints:^(MASConstraintMaker* make) {
        make.edges.mas_offset(0);
    }];

    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(self.picImageView.mas_right).mas_offset(5);
        make.right.mas_offset(-30);
        make.top.mas_equalTo(8);
        make.bottom.mas_equalTo(-8);
        make.height.mas_greaterThanOrEqualTo(28);
    }];
}

- (UILabel*)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

- (UIButton*)titleBtn
{
    if (!_titleBtn) {
        _titleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _titleBtn;
}

- (UIImageView*)picImageView
{
    if (!_picImageView) {
        _picImageView = [[UIImageView alloc] init];
    }
    return _picImageView;
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = ({
            UIImageView *imageView = [[UIImageView alloc] init];
            imageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"btn_more_gray")];
            imageView.contentMode = UIViewContentModeCenter;
            imageView;
        });
    }
    return _arrowImageView;
}

@end
